import us from '@/service/user.js'

export default {
    state: {
        isLogin: !!localStorage.getItem("token")
    },
    getters: {
    },
    mutations: {
        setLoginState(state, val) {
            state.isLogin = val
        }
    },
    actions: {
        login({ commit },userInfo){
            return us.login(userInfo).then(({token}) => {
                if(token){
                    commit('setLoginState',true)
                    localStorage.setItem("token",token)
                    return true
                }
                return false
            })
        },
        logout({ commit }){
            commit('setLoginState',false)
            localStorage.removeItem("token")
        }
    },
    modules: {
    }
}